package com.jason.seckill.controller;

import com.jason.seckill.service.IUserService;
import com.jason.seckill.vo.LoginVo;
import com.jason.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RequestMapping("/login")
@Slf4j
@Controller
public class LoginController {
    @Autowired
    private IUserService userService;


    //跳转登陆页面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(HttpServletRequest request, HttpServletResponse
            response, @Valid LoginVo loginVo) {
        RespBean login = userService.login(request, response, loginVo);
        return login;
    }
}
